pub mod crc32;
#[allow(unused_imports)]
pub use crc32::*;

#[allow(dead_code)]
pub fn slice_ngx_var_eq(a: &[u8], b: &[u8]) -> bool {
    if a.len() != b.len() {
        return false;
    }

    for (i, v) in a.iter().enumerate() {
        let mut ch_a = *v;
        if ch_a == b'-' {
            ch_a = b'_';
        }

        let mut ch_b = b[i];
        if ch_b == b'-' {
            ch_b = b'_';
        }

        if ch_a.to_ascii_lowercase() != ch_b.to_ascii_lowercase() {
            return false;
        }
    }

    true
}

#[cfg(test)]
mod tests {
    use crate::utils::slice::crc32_hash;

    use super::slice_ngx_var_eq;

    #[test]
    fn test_slice_eq() {
        let str1 = "ABCDEF-123";
        let str2 = "abcdef_123";

        assert!(slice_ngx_var_eq(str1.as_bytes(), str2.as_bytes()));
        assert!(str1.eq_ignore_ascii_case("abcdef-123"));

        let mut h = crc32fast::Hasher::new();
        h.update(str1.as_bytes());
        assert!(h.finalize() == crc32_hash(str1.as_bytes()));

        let mut h = crc32fast::Hasher::new();
        h.update(str2.as_bytes());
        assert!(h.finalize() == crc32_hash(str2.as_bytes()));
    }
}
